import requests
import json
if __name__ == '__main__':
    headers = {
        'User_Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.104 Safari/537.36'
    }
    kw = input('请输入想要翻译的单词：')
    url = 'https://fanyi.baidu.com/sug'
    data = {
        'kw':kw
    }
    response = requests.post(url=url,data=data,headers=headers)
    json_data = response.json()
    file_name = kw + '.json'
    f = open(file_name,'w',encoding='utf-8')
    json.dump(json_data,f,ensure_ascii=False)
    f.close()
    print('爬取完毕！')
